package study.nzy.com.studydemo;

import android.app.Activity;
import android.content.ContentValues;
import android.os.Bundle;
import android.view.View;

import study.nzy.com.studydemo.utils.DBHelper;

import static study.nzy.com.studydemo.utils.DBHelper.FIELD_AGE;
import static study.nzy.com.studydemo.utils.DBHelper.FIELD_NAME;
import static study.nzy.com.studydemo.utils.DBHelper.FIELD_PASSWORD;

public class DBActivity extends Activity{

    DBHelper dbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_db);
        dbHelper = new DBHelper(this);
    }

    public void addUser(View view) {
        ContentValues values = new ContentValues();
        values.put(FIELD_NAME,"lisi");
        values.put(FIELD_PASSWORD,"666666");
        values.put(FIELD_AGE,21);
        dbHelper.addUser(values);
    }

    public void deleteUser(View view) {
        int id = dbHelper.delete("lisi");
        System.out.println("DBActivity.deleteUser id:"+id);
    }

    public void updateUser(View view) {
        ContentValues values = new ContentValues();
        values.put(FIELD_PASSWORD,"77777");
        values.put(FIELD_AGE,19);
        dbHelper.updateByName("lisi",values);
    }

    public void findPassword(View view) {
        String pwd = dbHelper.findPasswordByName("lisi");
        System.out.println("DBActivity.findPassword pwd:"+pwd);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        dbHelper.closeDB();
    }
}